Thread: argv[]

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2010
    Location
    on some of the worst place on earth
    Posts
    105
    Quote Originally Posted by MK27 View Post
    Any kind of alphanumeric data can be in a character string, including integers.
    Code:
    char string[]="666";
    although the integers can be passed as strings they can't be processed as integers in the program.
    How to pass an integer number to main function via command line,so that i can find the factorial of the integer value???

  2. #2
    Registered User
    Join Date
    Jan 2008
    Posts
    79
    cmd: program_name 63 14 18 hello i am a string

    Code:
    int main (int argc, char *argv[]){
    
    int num = atoi(argv[1]);
    printf("%d",num);
    return 0;
    }
    result : 63

  3. #3
    Registered User
    Join Date
    Jan 2010
    Location
    on some of the worst place on earth
    Posts
    105
    Quote Originally Posted by mushy View Post
    cmd: program_name 63 14 18 hello i am a string

    Code:
    int main (int argc, char *argv[]){
    
    int num = atoi(argv[1]);
    printf("%d",num);
    return 0;
    }
    result : 63
    hmmmm.....quite a nice idea to work with!!!!! thanks , finally got a way to deal with

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is argv[] terminated by a NULL string?
    By dwks in forum C Programming
    Replies: 9
    Last Post: 07-24-2005, 10:24 AM
  2. when i would use char *argv[] and when char** argv[] ?
    By blue_gene in forum C Programming
    Replies: 17
    Last Post: 04-14-2004, 07:00 PM
  3. How do we cast an argv[]
    By Abdi in forum C Programming
    Replies: 10
    Last Post: 06-06-2002, 11:39 PM
  4. void main(), int main(), argc, argv[]????
    By Jonny M in forum C Programming
    Replies: 3
    Last Post: 03-06-2002, 09:12 AM
  5. How to use int argc, char* argv[] ?
    By gogo in forum C++ Programming
    Replies: 3
    Last Post: 11-21-2001, 01:21 PM